fx = f * Math.cos(angle)
fy = f * Math.sin(angle)
ax = fx / ball.m
ay = fy / ball.m
vx += ax
vy += ay
ball.x += vx
ball.y += vy



class Vector {
    constructor(x, y) {
        this.x = x
        this.y = y
    }
    scale(n) {
        this.x *= n
        this.y *= n
        return this
    }
    mag() {
        return Math.sqrt(this.x * this.x + this.y * this.y);
    }
    normalize() {
        var m = this.mag()
        if (m != 0 && m != 1) {
            this.scale(1 / m)
        }
        return this
    }
    add(other) {
        this.x += other.x
        this.y += other.y
        return this
    }
    sub(other) {
        this.x -= other.x
        this.y -= other.y
        return this
    }
    static add(one, other) {
        return new Vector(one.x + other.x, one.y + other.y)
    }
    static sub(one, other) {
        return new Vector(one.x - other.x, one.y - other.y)
    }
    static dist(one, other) {
        var dx = one.x - other.x
        var dy = one.y - other.y
        return Math.sqrt(dx * dx + dy * dy)
    }
}

;(function drawFrame() {
    window.requestAnimationFrame(drawFrame)
    context.clearRect(0, 0, canvas.width, canvas.height)
    var g = gravity(sun, earth)
    var a = g.scale(1 / earth.m)
    v.add(a)
    earth.p.add(v)
    earth.draw(context)
    sun.draw(context)}
)()

